#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 5010;
typedef long long ll;
ll money;
struct ss
{
	int p, a;
}s[N];
bool cmp(ss x, ss y)
{
	return x.p < y.p;
}
int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++)
		cin >> s[i].p >> s[i].a;
	sort(s, s + m, cmp);
	for (int i = 0; i < m; i++)
	{
		if (n - s[i].a >= 0)
		{
			n = n - s[i].a;
			money += s[i].p * s[i].a;
		}
		else
		{
			money += n * s[i].p;
			break;
		}
	}
	cout << money << endl;
	return 0;
}